#include "OptionsPanel.h"
#include <QLabel>
#include <QGroupBox>
#include <QSlider>

#include <QFileDialog>   //保存文件
#include "../src_dataProcessor/DataProcessor.h"
#include <QMessageBox>


OptionsPanel::OptionsPanel(ConfigUI* conf, QWidget* parent) : QWidget(parent) {
	ui.setupUi(this);
	m_config = conf;
	styleInit();
	setup_panelSlots();
}

OptionsPanel::~OptionsPanel() {}

void OptionsPanel::styleInit() {
	//设置选项面板样式
	//this->setStyleSheet(
	//    "QWidget {"
	//    "   background: #f0f0f0;"       // 背景色
	//    "   border: 1px solid #ccc;"    // 边框
	//    "   border-radius: 4px;"        // 圆角
	//    "}"
	//    "QLabel {"
	//    "   color: #333;"               // 标签文字颜色
	//    "   font-weight: bold;"
	//    "}"
	//    "QPushButton {"
	//    "   background: #4CAF50;"       // 按钮背景色
	//    "   color: white;"              // 按钮文字颜色
	//    "   border: none;"
	//    "   padding: 5px 10px;"
	//    "}"
	//    "QPushButton:hover {"
	//    "   background: #45a049;"       // 鼠标悬停时的按钮颜色
	//    "}"
	//);
}

void OptionsPanel::setup_panelSlots() {
	//1.复选框PPDT
	ui.checkShowFlyLines->setChecked(m_config->m_showFlyLines);
	connect(ui.checkShowFlyLines, &QCheckBox::toggled, this, [this](bool checked) {		// 显示飞线
		m_config->m_showFlyLines = checked;
		paintChanged();
		});
	ui.checkShowWires->setChecked(m_config->m_showWires);
	connect(ui.checkShowWires, &QCheckBox::checkStateChanged, this, [this]() {			// 显示走线结果
		m_config->m_showWires = ui.checkShowWires->checkState() == Qt::Checked;
		paintChanged();
		});
	ui.checkShowObs->setChecked(m_config->m_showObss);
	connect(ui.checkShowObs, &QCheckBox::checkStateChanged, this, [this]() {		// 显示障碍物
		m_config->m_showObss = ui.checkShowObs->checkState() == Qt::Checked;
		paintChanged();
		});
	ui.checkShowCorners->setChecked(m_config->m_showCorners);
	connect(ui.checkShowCorners, &QCheckBox::checkStateChanged, this, [this]() {		// 显示规划点
		m_config->m_showCorners = ui.checkShowCorners->checkState() == Qt::Checked;
		paintChanged();
		});
	ui.checkShowPathPts->setChecked(m_config->m_showPathPts);
	connect(ui.checkShowPathPts, &QCheckBox::checkStateChanged, this, [this]() {		// 显示路径点
		m_config->m_showPathPts = ui.checkShowPathPts->checkState() == Qt::Checked;
		paintChanged();
		});
	ui.checkShowResPts->setChecked(m_config->m_show_resPts);
	connect(ui.checkShowResPts, &QCheckBox::checkStateChanged, this, [this]() {			// 显示Res点
		m_config->m_show_resPts = ui.checkShowResPts->checkState() == Qt::Checked;
		paintChanged();
		});

	//2..复选框Polygon
	ui.checkShowGrid->setChecked(m_config->m_showGrids);
	connect(ui.checkShowGrid, &QCheckBox::checkStateChanged, this, [this]() {		// 显示路径点
		m_config->m_showGrids = ui.checkShowGrid->checkState() == Qt::Checked;
		paintChanged();
		});
	ui.checkOnGrid->setChecked(m_config->m_onGrids);
	connect(ui.checkOnGrid, &QCheckBox::checkStateChanged, this, [this]() {		// 显示路径点
		m_config->m_onGrids = ui.checkOnGrid->checkState() == Qt::Checked;
		paintChanged();
		});
	ui.checkPostProcess->setChecked(m_config->m_postOn);
	connect(ui.checkPostProcess, &QCheckBox::checkStateChanged, this, [this]() {		// 显示路径点
		m_config->m_postOn = ui.checkPostProcess->checkState() == Qt::Checked;
		paintChanged();
		});

	//3.按钮PPDT
	connect(ui.openResBt, &QPushButton::clicked, this, [this]() {			// 打开Ren文件，用于查看
		emit open_res_request_signal();
		});
	connect(ui.openLayoutBt, &QPushButton::clicked, this, [this]() {		// 打开Layout文件，用于寻路
		emit open_layout_request_signal();
		});
	connect(ui.resetBt, &QPushButton::clicked, this, [this]() {				// 复位重置
		emit reset_request_signal();
		});
    connect(ui.randPinBt, &QPushButton::clicked, this, [this]() {			// 随机pin
		emit random_pin_request_signal();
		});
    connect(ui.pinDecreaseBt, &QPushButton::clicked, this, [this]() {		// 减少pin
		emit pin_decrease_request_signal();
		});
    connect(ui.pinIncreaseBt, &QPushButton::clicked, this, [this]() {		// 增加pin
		emit pin_increase_request_signal();
		});
	connect(ui.saveCaseBt, &QPushButton::clicked, this, [this]() {			// 保存case
		emit save_case_request_signal();
		});
	connect(ui.saveImageBt, &QPushButton::clicked, this, [this]() {			// 保存图片
		emit save_image_request_signal();
		});
	connect(ui.writePreBt, &QPushButton::clicked, this, [this]() {			// 保存预处理结果
		emit write_pre_request_signal();
		});
	connect(ui.addResBt, &QPushButton::clicked, this, [this]() {			// 追加保存结果
		emit write_res_request_signal();
		});
    connect(ui.PPDTRunBt, &QPushButton::clicked, this, [this]() {				// 运行PPDT寻路算法
		emit PPTT_run_request_signal();
		});
	connect(ui.polyRunBt, &QPushButton::clicked, this, [this]() {				// 运行PPDT寻路算法
		emit poly_run_request_signal();
		});

	//4.按钮Polygon
}
